package cn.com.sbell.vss.csg.vap;

import org.dom4j.Element;

import cn.com.sbell.vss.csg.vap.bean.LogInfo;
import cn.com.sbell.vss.csg.vap.bean.LogRequest;
import cn.com.sbell.vss.csg.vsclient.VsClient;
import cn.com.sbell.vss.csg.vsclient.util.BeanValidator;
import cn.com.sbell.vss.csg.vsclient.util.PropertiesHolder;

public class GetVsLog extends ProtectedVsCommander {

	
	protected Element executeCommand(VsClient vsClient,
			PropertiesHolder holder, Element root) {
		LogRequest logRequest = (LogRequest) holder.populate(new LogRequest());
		BeanValidator
				.validateNotNull(logRequest, new String[] { "selectMode" });

		if (logRequest.getSelectMode().intValue() == 1) {
			BeanValidator.validateNotNull(logRequest, new String[] {
					"majorType", "minorType" });
		} else if (logRequest.getSelectMode().intValue() == 2) {
			BeanValidator.validateNotNull(logRequest, new String[] {
					"startTime", "stopTime" });
		} else {
			BeanValidator.validateNotNull(logRequest, new String[] {
					"majorType", "minorType", "startTime", "stopTime" });
		}
		LogInfo[] logInfo=vsClient.getVsLog(logRequest);
		if(logInfo!=null && logInfo.length>0){
			for (int i = 0; i < logInfo.length; i++) {
				Element log = root.addElement("log");
				log.addElement("majorType").addText(toString(logInfo[i].getMajorType()));
				log.addElement("minorType").addText(toString(logInfo[i].getMinorType()));
				log.addElement("logTime").addText(toString(logInfo[i].getLogTime()));
				log.addElement("logData").addText(toString(logInfo[i].getLogData()));				
			}			
		}
		return root;
	}
}
